package com.example.ireader;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class CategoryActivity extends AppCompatActivity {
    private int POS=0;

    private List<Category_First_Left_Fragment_Item> category_first_left_fragment_item_List = new ArrayList<>();

    private List<Category_First_Right_Fragment_Item> category_first_right_fragment_item_List1 = new ArrayList<>();
    private List<Category_First_Right_Fragment_Item> category_first_right_fragment_item_List2 = new ArrayList<>();
    private List<Category_First_Right_Fragment_Item> category_first_right_fragment_item_List3 = new ArrayList<>();
    private List<Category_First_Right_Fragment_Item> category_first_right_fragment_item_List4 = new ArrayList<>();
    private List<Category_First_Right_Fragment_Item> category_first_right_fragment_item_List5 = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category);
        //-----------------------------------------隐藏标题---------------------------------------//
        ActionBar actionBar = getSupportActionBar();
        if (actionBar!=null)
            actionBar.hide();
        TextView textView = (TextView)findViewById(R.id.title_text) ;
        textView.setText("分类");
        //-----------------------------------------隐藏标题---------------------------------------//

        // ---------------------------------Category_First_Page部分-------------------------------//
        init_First_left();//初始化1
        init_First_right("男频");//初始化2

        replaceLeftFragment();
        replaceRightFragment("男频");
        //--------------------------------Category_First_Page部分---------------------------------//
    }

    private void initAdapter (String string){
        RecyclerView first_recyclerView_right = (RecyclerView)findViewById(R.id.category_first_page_right_recycler_view);
        LinearLayoutManager layoutManager2 = new LinearLayoutManager(this);
        first_recyclerView_right.setLayoutManager(layoutManager2);
        Category_First_Right_Fragment_Adapter category_first_right_fragment_adapter;
        switch (string){
            case "男频":
                category_first_right_fragment_adapter = new Category_First_Right_Fragment_Adapter(category_first_right_fragment_item_List1);
                first_recyclerView_right.setAdapter(category_first_right_fragment_adapter);
                break;
            case "女频":
                category_first_right_fragment_adapter = new Category_First_Right_Fragment_Adapter(category_first_right_fragment_item_List2);
                first_recyclerView_right.setAdapter(category_first_right_fragment_adapter);
                break;
            case "杂志":
                category_first_right_fragment_adapter = new Category_First_Right_Fragment_Adapter(category_first_right_fragment_item_List3);
                first_recyclerView_right.setAdapter(category_first_right_fragment_adapter);
                break;
            case "漫画":
                category_first_right_fragment_adapter = new Category_First_Right_Fragment_Adapter(category_first_right_fragment_item_List4);
                first_recyclerView_right.setAdapter(category_first_right_fragment_adapter);
                break;
            case "出版":
                category_first_right_fragment_adapter = new Category_First_Right_Fragment_Adapter(category_first_right_fragment_item_List5);
                first_recyclerView_right.setAdapter(category_first_right_fragment_adapter);
                break;
            default:
                break;
        }
    }

    public void getPOS(int POS){
        this.POS = POS;
    }

    public  void replaceLeftFragment(){
        //获取RecyclerView实例
        RecyclerView first_recyclerView_left = (RecyclerView)findViewById(R.id.category_first_page_left_recycler_view);
        //创建LinearLayoutManager并设置到RecyclerView当中
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(this);
        first_recyclerView_left.setLayoutManager(layoutManager1);
        //创建适配器实例
        Category_First_Left_Fragment_Adapter category_first_left_fragment_adapter = new Category_First_Left_Fragment_Adapter(category_first_left_fragment_item_List,this,POS);
        //将数据放入适配器
        first_recyclerView_left.setAdapter(category_first_left_fragment_adapter);
    }

    public void replaceRightFragment(String string){
        switch (string){
            case "男频":
                initAdapter("男频");
                break;
            case "女频":
                initAdapter("女频");
                break;
            case "杂志":
                initAdapter("杂志");
                break;
            case "漫画":
                initAdapter("漫画");
                break;
            case "出版":
                initAdapter("出版");
                break;
            default:
                break;
        }
    }

    //--------------------------------------初始化数据函数定义------------------------------------//
    private void init_First_left(){
        Category_First_Left_Fragment_Item item1 = new Category_First_Left_Fragment_Item("男频");
        category_first_left_fragment_item_List.add(item1);
        Category_First_Left_Fragment_Item item2 = new Category_First_Left_Fragment_Item("女频");
        category_first_left_fragment_item_List.add(item2);
        Category_First_Left_Fragment_Item item3 = new Category_First_Left_Fragment_Item("杂志");
        category_first_left_fragment_item_List.add(item3);
        Category_First_Left_Fragment_Item item4 = new Category_First_Left_Fragment_Item("漫画");
        category_first_left_fragment_item_List.add(item4);
        Category_First_Left_Fragment_Item item5 = new Category_First_Left_Fragment_Item("出版");
        category_first_left_fragment_item_List.add(item5);
    }

    private void init_First_right(String string){
        switch (string){
            case "男频":
                Category_First_Right_Fragment_Item item1_1 = new Category_First_Right_Fragment_Item("1玄幻",R.drawable.yxuanhuan);
                category_first_right_fragment_item_List1.add(item1_1);
                Category_First_Right_Fragment_Item item1_2 = new Category_First_Right_Fragment_Item("2武侠",R.drawable.ywuxia);
                category_first_right_fragment_item_List1.add(item1_2);
                Category_First_Right_Fragment_Item item1_3 = new Category_First_Right_Fragment_Item("3科幻",R.drawable.ykehuan);
                category_first_right_fragment_item_List1.add(item1_3);
                Category_First_Right_Fragment_Item item1_4 = new Category_First_Right_Fragment_Item("4都市",R.drawable.ydushi);
                category_first_right_fragment_item_List1.add(item1_4);
                Category_First_Right_Fragment_Item item1_5 = new Category_First_Right_Fragment_Item("5校园",R.drawable.yxiaoyuan);
                category_first_right_fragment_item_List1.add(item1_5);
                Category_First_Right_Fragment_Item item1_6 = new Category_First_Right_Fragment_Item("6历史",R.drawable.ylishi);
                category_first_right_fragment_item_List1.add(item1_6);
                Category_First_Right_Fragment_Item item1_7 = new Category_First_Right_Fragment_Item("7军事",R.drawable.yjunshi);
                category_first_right_fragment_item_List1.add(item1_7);
                Category_First_Right_Fragment_Item item1_8 = new Category_First_Right_Fragment_Item("8游戏",R.drawable.yyouxi);
                category_first_right_fragment_item_List1.add(item1_8);
                Category_First_Right_Fragment_Item item1_9 = new Category_First_Right_Fragment_Item("9竞技",R.drawable.yjingji);
                category_first_right_fragment_item_List1.add(item1_9);
            case "女频":
                Category_First_Right_Fragment_Item item2_1 = new Category_First_Right_Fragment_Item("1言情",R.drawable.eyanqing);
                category_first_right_fragment_item_List2.add(item2_1);
                Category_First_Right_Fragment_Item item2_2 = new Category_First_Right_Fragment_Item("2校园",R.drawable.exiaoyuan);
                category_first_right_fragment_item_List2.add(item2_2);
                Category_First_Right_Fragment_Item item2_3 = new Category_First_Right_Fragment_Item("3同人",R.drawable.etongren);
                category_first_right_fragment_item_List2.add(item2_3);
                Category_First_Right_Fragment_Item item2_4 = new Category_First_Right_Fragment_Item("4悬疑",R.drawable.exuanyi);
                category_first_right_fragment_item_List2.add(item2_4);
                Category_First_Right_Fragment_Item item2_5 = new Category_First_Right_Fragment_Item("5惊悚",R.drawable.ejingsong);
                category_first_right_fragment_item_List2.add(item2_5);
                Category_First_Right_Fragment_Item item2_6 = new Category_First_Right_Fragment_Item("6次元",R.drawable.eciyuan      );
                category_first_right_fragment_item_List2.add(item2_6);
            case "杂志":
                Category_First_Right_Fragment_Item item3_1 = new Category_First_Right_Fragment_Item("1文学",R.drawable.sawenxue);
                category_first_right_fragment_item_List3.add(item3_1);
                Category_First_Right_Fragment_Item item3_2 = new Category_First_Right_Fragment_Item("2人物",R.drawable.sarenwu);
                category_first_right_fragment_item_List3.add(item3_2);
                Category_First_Right_Fragment_Item item3_3 = new Category_First_Right_Fragment_Item("3生活",R.drawable.sashenghuo);
                category_first_right_fragment_item_List3.add(item3_3);
                Category_First_Right_Fragment_Item item3_4 = new Category_First_Right_Fragment_Item("4娱乐",R.drawable.sayule);
                category_first_right_fragment_item_List3.add(item3_4);
                Category_First_Right_Fragment_Item item3_5 = new Category_First_Right_Fragment_Item("5军政",R.drawable.sajunzheng);
                category_first_right_fragment_item_List3.add(item3_5);
                Category_First_Right_Fragment_Item item3_6 = new Category_First_Right_Fragment_Item("6经济",R.drawable.sajingji);
                category_first_right_fragment_item_List3.add(item3_6);
                Category_First_Right_Fragment_Item item3_7 = new Category_First_Right_Fragment_Item("7旅游",R.drawable.salvyou);
                category_first_right_fragment_item_List3.add(item3_7);
                Category_First_Right_Fragment_Item item3_8 = new Category_First_Right_Fragment_Item("8科技",R.drawable.sakeji);
                category_first_right_fragment_item_List3.add(item3_8);
                Category_First_Right_Fragment_Item item3_9 = new Category_First_Right_Fragment_Item("9体育",R.drawable.satiyu);
                category_first_right_fragment_item_List3.add(item3_9);
                Category_First_Right_Fragment_Item item3_10 = new Category_First_Right_Fragment_Item("10学习",R.drawable.saxuexi);
                category_first_right_fragment_item_List3.add(item3_10);
                Category_First_Right_Fragment_Item item3_11 = new Category_First_Right_Fragment_Item("11小说",R.drawable.saxiaoshuo);
                category_first_right_fragment_item_List3.add(item3_11);
                Category_First_Right_Fragment_Item item3_12 = new Category_First_Right_Fragment_Item("12女性",R.drawable.sanvxing);
                category_first_right_fragment_item_List3.add(item3_12);
                Category_First_Right_Fragment_Item item3_13 = new Category_First_Right_Fragment_Item("13漫画",R.drawable.samanhua);
                category_first_right_fragment_item_List3.add(item3_13);
                Category_First_Right_Fragment_Item item3_14 = new Category_First_Right_Fragment_Item("14其他",R.drawable.saqita);
                category_first_right_fragment_item_List3.add(item3_14);
            case "漫画":
                Category_First_Right_Fragment_Item item4_1 = new Category_First_Right_Fragment_Item("1搞笑",R.drawable.sigaoxiao);
                category_first_right_fragment_item_List4.add(item4_1);
                Category_First_Right_Fragment_Item item4_2 = new Category_First_Right_Fragment_Item("2惊悚",R.drawable.sijingsong);
                category_first_right_fragment_item_List4.add(item4_2);
                Category_First_Right_Fragment_Item item4_3 = new Category_First_Right_Fragment_Item("3玄幻",R.drawable.sixuanhuan);
                category_first_right_fragment_item_List4.add(item4_3);
                Category_First_Right_Fragment_Item item4_4 = new Category_First_Right_Fragment_Item("4小说改",R.drawable.sixiaoshuogai);
                category_first_right_fragment_item_List4.add(item4_4);
                Category_First_Right_Fragment_Item item4_5 = new Category_First_Right_Fragment_Item("5真人漫画",R.drawable.sizhenren);
                category_first_right_fragment_item_List4.add(item4_5);
                Category_First_Right_Fragment_Item item4_6 = new Category_First_Right_Fragment_Item("6科幻",R.drawable.sikehuan);
                category_first_right_fragment_item_List4.add(item4_6);
                Category_First_Right_Fragment_Item item4_7 = new Category_First_Right_Fragment_Item("7热血",R.drawable.sirexue);
                category_first_right_fragment_item_List4.add(item4_7);
                Category_First_Right_Fragment_Item item4_8 = new Category_First_Right_Fragment_Item("8恋爱",R.drawable.silianai);
                category_first_right_fragment_item_List4.add(item4_8);
            case "出版":
                Category_First_Right_Fragment_Item item5_1 = new Category_First_Right_Fragment_Item("1人物传记",R.drawable.wzhuanji);
                category_first_right_fragment_item_List5.add(item5_1);
                Category_First_Right_Fragment_Item item5_2 = new Category_First_Right_Fragment_Item("2文学作品",R.drawable.wwenxue);
                category_first_right_fragment_item_List5.add(item5_2);
                Category_First_Right_Fragment_Item item5_3 = new Category_First_Right_Fragment_Item("3社会科学",R.drawable.wsheke);
                category_first_right_fragment_item_List5.add(item5_3);
                Category_First_Right_Fragment_Item item5_4 = new Category_First_Right_Fragment_Item("4其他",R.drawable.wqita);
                category_first_right_fragment_item_List5.add(item5_4);
            default:
                break;
        }
    }

    //--------------------------------------初始化数据函数定义------------------------------------//
}
